<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  
  
  <link rel="shortcut icon" href="img/favicon.ico">
  <title>基本地图操作 - Minetest Modding Books(中文版)</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700" />

  <link rel="stylesheet" href="css/theme.css" />
  <link rel="stylesheet" href="css/theme_extra.css" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/github.min.css" />
  
  <script>
    // Current page data
    var mkdocs_page_name = "\u57fa\u672c\u5730\u56fe\u64cd\u4f5c";
    var mkdocs_page_input_path = "9.\u57fa\u672c\u5730\u56fe\u64cd\u4f5c.md";
    var mkdocs_page_url = null;
  </script>
  
  <script src="js/jquery-2.1.1.min.js" defer></script>
  <script src="js/modernizr-2.8.3.min.js" defer></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/highlight.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script> 
</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
    <div class="wy-side-scroll">
      <div class="wy-side-nav-search">
        <a href="index.html" class="icon icon-home"> Minetest Modding Books(中文版)</a>
        <div role="search">
  <form id ="rtd-search-form" class="wy-form" action="./search.html" method="get">
      <input type="text" name="q" placeholder="Search docs" title="Type search term here" />
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="index.html">首页</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="1.%E8%AF%91%E8%80%85%E5%BA%8F.html">译者序</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="2.%E5%89%8D%E8%A8%80.html">前言</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="3.%E5%85%A5%E9%97%A8.html">入门</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="4.Lua%E8%84%9A%E6%9C%AC.html">Lua脚本</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="5.%E8%8A%82%E7%82%B9%E3%80%81%E7%89%A9%E5%93%81%E5%92%8C%E5%88%B6%E4%BD%9C.html">节点、物品与制作</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="6.%E5%88%B6%E4%BD%9C%E6%9D%90%E8%B4%A8.html">制作贴图</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="7.%E8%8A%82%E7%82%B9%E7%BB%98%E5%9B%BE%E7%B1%BB%E5%9E%8B.html">节点绘图类型</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="8.%E7%89%A9%E5%93%81%E6%A0%8F%E5%92%8C%E8%83%8C%E5%8C%85.html">物品栏和背包</a>
                    </li>
                </ul>
                <ul class="current">
                    <li class="toctree-l1 current"><a class="reference internal current" href="9.%E5%9F%BA%E6%9C%AC%E5%9C%B0%E5%9B%BE%E6%93%8D%E4%BD%9C.html">基本地图操作</a>
    <ul class="current">
    <li class="toctree-l2"><a class="reference internal" href="#_2">地图结构</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#_3">读取</a>
        <ul>
    <li class="toctree-l3"><a class="reference internal" href="#_4">读取节点</a>
    </li>
    <li class="toctree-l3"><a class="reference internal" href="#_5">查找节点</a>
    </li>
        </ul>
    </li>
    </ul>
                    </li>
                </ul>
      </div>
    </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="index.html">Minetest Modding Books(中文版)</a>
      </nav>

      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="index.html">Docs</a> &raquo;</li>
    
      
    
    <li>基本地图操作</li>
    <li class="wy-breadcrumbs-aside">
      
    </li>
  </ul>
  
  <hr/>
</div>

          <div role="main">
            <div class="section">
              
                <h1 id="_1">基本地图操作</h1>
<p>在这一章节中，你将会学到如何在地图上进行基本操作。</p>
<h2 id="_2">地图结构</h2>
<p>Minetest地图被分成多个图块，每个图块是一个16大小的立方体。当玩家在地图上移动时，地图块被创建、加载和卸载。地图中尚未加载的区域充满了ignore节点，这是一个不可选择的占位符节点。空旷的空间里充满了空气节点，一个你可以穿过的隐形节点。<br>
加载的地图块通常称为活动块。活动块可以被mod或玩家读写，并且有活动实体。引擎还执行地图上的操作，例如执行液体物理。<br>
地图块可以从世界数据库加载或生成。地图块将生成到地图生成限制（<code>mapgen_limit</code>），默认设置为最大值31000。但是，现有的地图块可以在生成限制之外从世界数据库加载。</p>
<h2 id="_3">读取</h2>
<h3 id="_4">读取节点</h3>
<p>你可以通过坐标来找取地图上的节点：</p>
<pre><code class="language-lua">local node = minetest.get_node({ x = 1, y = 3, z = 4 })
print(dump(node)) --&gt; { name=.., param1=.., param2=.. }
</code></pre>
<p>如果坐标值是小数点，将会被四舍五入到节点。这些函一直返回包含节点信息的表。<br>
* <code>name</code> 节点名称，如果该区域没有加载，将会被忽略。
* <code>param1</code> 请看节点定义，通常用于灯光。
* <code>param2</code> 请看节点定义。</p>
<p>值得注意的是，如果包含块处于非活动状态，则函数不会加载该块，而是返回一个<code>name</code>为<code>ignore</code>的表。<br>
你可以用<code>minetest.get_node_or_nil</code>，它将返回<code>nil</code>，而不是名为<code>ignore</code>的表。但是，它仍然无法加载块。如果块实际包含<code>ignore</code>，则仍可能返回<code>ignore</code>。这将发生在地图生成限制（<code>mapgen_limit</code>）定义的地图边缘附近。<br></p>
<h3 id="_5">查找节点</h3>
<p>Minetest提供了许多helper函数来加速常见的map操作。其中最常用的是查找节点。<br>
例如，假设我们想让某种植物在黄石附近生长得更好；您需要搜索任何附近的黄石节点，并相应地调整增长率。
<code>minetest.find_node_near</code>将会返回第一个在指定半径范围内匹配所给的单个节点名称或者节点合集的节点。在以下的例子中，我们将会在该位置的5个方块的范围内找到黄石节点。</p>
<pre><code class="language-lua">local grow_speed = 1
local node_pos   = minetest.find_node_near(pos, 5, { &quot;default:mese&quot; })
if node_pos then
    minetest.chat_send_all(&quot;Node found at: &quot; .. dump(node_pos))
    grow_speed = 2
end
</code></pre>
<p>比如说，附近的黄石越多生长速率就越快。你可以用一个函数，来寻找该区域内的多个指定节点：</p>
<pre><code class="language-lua">local pos1       = vector.subtract(pos, { x = 5, y = 5, z = 5 })
local pos2       = vector.add(pos, { x = 5, y = 5, z = 5 })
local pos_list   =
        minetest.find_nodes_in_area(pos1, pos2, { &quot;default:mese&quot; })
local grow_speed = 1 + #pos_list
</code></pre>
<p>现在可以让附近黄石方块数量决定生长率。<br>
请注意，我们是用比较与位置的平方距离的，而不是通过平方根来获得实际距离的，这是因为计算机算平方根的计算成本很高，所以应该尽量避免。
这里有两个更多相关的函数变种，比如<code>find_nodes_with_meta</code>，<code>find_nodes_in_area_under_air</code>，其实跟上面所提到的案例差不多。：<br></p>
<pre><code class="language-lua">local grow_speed = 1
local node_pos   = minetest.find_node_near(pos, 5, { &quot;default:mese&quot; })
if node_pos then
    minetest.chat_send_all(&quot;Node found at: &quot; .. dump(node_pos))
    grow_speed = 2
end
</code></pre>
<p>比如说，增长率越高，附近黄石就越多。然后，您应该使用一个可以在该区域中查找多个节点的函数：</p>
<pre><code class="language-lua">local pos1       = vector.subtract(pos, { x = 5, y = 5, z = 5 })
local pos2       = vector.add(pos, { x = 5, y = 5, z = 5 })
local pos_list   =
        minetest.find_nodes_in_area(pos1, pos2, { &quot;default:mese&quot; })
local grow_speed = 1 + #pos_list
</code></pre>
<p>（该文章还没翻译完......）</p>
              
            </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
      
        <a href="8.%E7%89%A9%E5%93%81%E6%A0%8F%E5%92%8C%E8%83%8C%E5%8C%85.html" class="btn btn-neutral" title="物品栏和背包"><span class="icon icon-circle-arrow-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <!-- Copyright etc -->
    
  </div>

  Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
      
        </div>
      </div>

    </section>

  </div>

  <div class="rst-versions" role="note" aria-label="versions">
  <span class="rst-current-version" data-toggle="rst-current-version">
    
    
      <span><a href="8.%E7%89%A9%E5%93%81%E6%A0%8F%E5%92%8C%E8%83%8C%E5%8C%85.html" style="color: #fcfcfc">&laquo; Previous</a></span>
    
    
  </span>
</div>
    <script>var base_url = '.';</script>
    <script src="js/theme_extra.js" defer></script>
    <script src="js/theme.js" defer></script>
      <script src="search/main.js" defer></script>
    <script defer>
        window.onload = function () {
            SphinxRtdTheme.Navigation.enable(true);
        };
    </script>

</body>
</html>
